#include <xp/bas/string.h>
#include <xp/bas/stdlib.h>
#include <xp/bas/stdio.h>
#ifdef _WIN32
#include <tchar.h>
#endif

int xp_main (int argc, xp_char_t* argv[])
{
	int n1, n2;
	xp_size_t len;

	if (argc != 4) {
		xp_fprintf (xp_stderr, 
			XP_TEXT("usage: %s string1 string2 len\n"), argv[0]);
		return -1;
	}

	len = (xp_size_t) xp_strtoulong (argv[3]);

	n1 = xp_strcmp (argv[1], argv[2]);
	xp_printf (XP_TEXT("xp_strcmp (%s, %s) => %d\n"), 
		argv[1], argv[2], n1);
#ifdef _WIN32
	n2 = _tcscmp (argv[1], argv[2]);
	n2 = (n2 > 0)? 1: ((n2 == 0)? 0: -1);
	xp_printf (XP_TEXT("_tcscmp (%s, %s) => %d\n"), 
		argv[1], argv[2], n2);
#endif
	xp_printf (XP_TEXT("---[%s]-----------------\n\n"), 
		((n1 == n2)? XP_TEXT("OK"): XP_TEXT("ERR")));



	n1 = xp_strcmpn (argv[1], argv[2], len);
	xp_printf (XP_TEXT("xp_strcmpn (%s, %s, %llu) => %d\n"), 
		argv[1], argv[2], (unsigned long long)len, n1);
#ifdef _WIN32
	n2 = _tcsncmp (argv[1], argv[2], len);
	n2 = (n2 > 0)? 1: ((n2 == 0)? 0: -1);
	xp_printf (XP_TEXT("_tcsncmp (%s, %s, %llu) => %d\n"), 
		argv[1], argv[2], (unsigned long long)len, n2);
#endif
	xp_printf (XP_TEXT("---[%s]-----------------\n\n"), 
		((n1 == n2)? XP_TEXT("OK"): XP_TEXT("ERR")));



	n1 = xp_strcasecmp (argv[1], argv[2]);
	xp_printf (XP_TEXT("xp_strcasecmpn (%s, %s) => %d\n"),
		argv[1], argv[2], n1);
#ifdef _WIN32
	n2 = _tcsicmp (argv[1], argv[2]);
	n2 = (n2 > 0)? 1: ((n2 == 0)? 0: -1);
	xp_printf (XP_TEXT("_tcsicmp (%s, %s) => %d\n"), 
		argv[1], argv[2], n2);
#endif
	xp_printf (XP_TEXT("---[%s]-----------------\n\n"), 
		((n1 == n2)? XP_TEXT("OK"): XP_TEXT("ERR")));



	n1 = xp_strcasecmpn (argv[1], argv[2], len);
	xp_printf (XP_TEXT("xp_strcasecmpn (%s, %s, %llu) => %d\n"),
		argv[1], argv[2], (unsigned long long)len, n1);
#ifdef _WIN32
	n2 = _tcsnicmp (argv[1], argv[2], len);
	n2 = (n2 > 0)? 1: ((n2 == 0)? 0: -1);
	xp_printf (XP_TEXT("_tcsnicmp (%s, %s, %llu) => %d\n"), 
		argv[1], argv[2], (unsigned long long)len, n2);
#endif
	xp_printf (XP_TEXT("---[%s]-----------------\n\n"), 
		((n1 == n2)? XP_TEXT("OK"): XP_TEXT("ERR")));

	return 0;
}

